//
//  ChaKanXiaViewController.m
//  yonghu
//
//  Created by 浪尖渝力 on 2018/2/25.
//  Copyright © 2018年 com.DJS. All rights reserved.
//

#import "ChaKanXiaViewController.h"


@interface ChaKanXiaViewController ()<UIWebViewDelegate>

@end

@implementation ChaKanXiaViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self wr_setNavBarBackgroundAlpha:0];
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
    
    NSString *Path=[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
    NSString *filename=[Path stringByAppendingPathComponent:_file];
    //    判断沙盒中是否存在要读取的文件，若不存在，将元目录中的文件拷贝到沙盒中
    
    //如果文件不存在，则将目录中的文件复制到沙盒中
    if (![[NSFileManager defaultManager] fileExistsAtPath:filename]) {
        NSString *source=[[NSBundle mainBundle]pathForResource:[_file substringToIndex:_file.length-5] ofType:@"docx"];
        NSData *data=[[NSFileManager defaultManager]contentsAtPath:source];
        if (![[NSFileManager defaultManager]createFileAtPath:filename contents:data attributes:nil]) {
            NSLog(@"文件复制失败");
            return;
        }
    }
    
    //创建WebView
    UIWebView *webView=[[UIWebView alloc] initWithFrame:self.view.frame];
    NSURL *url=[NSURL fileURLWithPath:filename];
    NSURLRequest *request=[NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    [webView setScalesPageToFit:YES];
    webView.delegate = self;
    [self.view addSubview:webView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
